'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE ,UUID ,UUIDV4} = app.Sequelize;

  const DictionaryDetail = app.model.define('dictionary_detail', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    parent_id: {
      type: UUID,
      allowNull: false,
      defaultValue: UUIDV4,
      references: {
        model: 'dictionary',
        key: 'id'
      }
    },
    dict_key: { type: STRING(255), allowNull: false },
    dict_value: { type: STRING(255), allowNull: false },
    sort: INTEGER,
    icon: STRING(255),
    description: STRING(255),
    created_at: DATE,
    updated_at: DATE,
  }, {
    tableName: 'dictionary_detail',
    timestamps: true,
  });

  DictionaryDetail.associate = function() {
    app.model.DictionaryDetail.belongsTo(app.model.Dictionary, { foreignKey: 'parent_id' });
  };

  return DictionaryDetail;
};
